<?php
class Events extends CI_Model{
	
	public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	/**
	 * Kiem tra 1 su kien da co trong db hay chua
	 * @param  $event_id id cua event
	 */
	public function checkExist($event_id){
		$this->db->where("event_id",$event_id);
		if($this->db->count_all_results('events') > 0){
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	
	/**
	 * Return 1 su kien ton tai trong db
	 * @param unknown_type $event_id
	 */
	public function getEvent($event_id){
		$query = $this->db->get_where("events",array('event_id'=>$event_id));
		return $query->result();
	}
	
	public function insertEvent($events){
		if($this->checkExist($events['event_id'])){
			return FALSE;
		}else{
			$this->db->insert('events',$events);
			return TRUE;
		}
	}
	
	public function updateEvent($events){
		if($this->checkExist($events['event_id'])){
			$this->db->where('event_id',$events['event_id']);
			$this->db->update('events',$events);
			return TRUE;			
		}else{
			return FALSE;
		}
	}
}